﻿@using LunwenYun.Infrastructure.Entities.Entity;
@using LunwenYun.Infrastructure.Entities.Enum;
@{
    User user = null;
    if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
        user = new User().Find(HttpContext.Current.User.Identity.Name);
    }

    if (user != null && user.SystemRole == LunwenYun.Infrastructure.Entities.Enum.UserRole.PaperAgent)
    {
        Layout = "~/Views/Shared/_o_Main.cshtml";
    }
    else
    {
        Layout = "~/Views/Shared/_m_Main.cshtml";
    }
}
@section head{
    <script type="text/javascript" src="/Scripts/plug.js"></script>
}
<!-- Filter -->
<div class="mini-layout graybg">
    <form id="mlistform" action="/" method="post">
    <input id="hidind" type="hidden" name="ind" value="@ViewBag.IndType" />
    <input id="hidapt" type="hidden" name="apt" value="@ViewBag.Aptitude" />
    <input id="hidlang" type="hidden" name="lang" value="@ViewBag.Language" />
    <div class="row">
        <div class="span1">
            <span class="btn btn-info prebtn">行业</span>
        </div>
        <div class="span10">
            <span class="float-left">
                <ul id="indtypenav" class="nav nav-pills">
                    <li><a onclick="triggerIndType('-1',this)" href="javascript:;">所有</a> </li>
                    <script type="text/javascript">
                        for (var i = 0, len = data.IndType.length; i < len; i++) {
                            document.writeln('<li><a href="javascript:;" onclick="triggerIndType(' + data.IndType[i].value + ',this)">' + data.IndType[i].name + '</a></li>');
                        }
                    </script>
                </ul>
            </span>
        </div>
    </div>
    <div class="row">
        <div class="span1">
            <span class="btn btn-info prebtn">类型</span>
        </div>
        <div class="span10">
            <span class="float-left">
                <ul id="aptnav" class="nav nav-pills">
                    <li><a href="javascript:;" onclick="triggerApt(-1,this)">所有</a></li>
                    <script type="text/javascript">
                        for (var i = 0, len = data.Aptitude.length; i < len; i++) {
                            document.writeln('<li><a href="javascript:;" onclick="triggerApt(' + data.Aptitude[i].value + ',this)">' + data.Aptitude[i].name + '</a></li>');
                        }
                    </script>
                </ul>
            </span>
        </div>
    </div>
    <div class="row">
        <div class="span1">
            <span class="btn btn-info prebtn">语言</span>
        </div>
        <div class="span10">
            <span class="float-left">
                <ul id="aptlang" class="nav nav-pills">
                    <li><a href="javascript:;" onclick="triggerLanguage(-1,this)">所有</a></li>
                    <script type="text/javascript">
                        for (var i = 0, len = data.Language.length; i < len; i++) {
                            document.writeln('<li><a href="javascript:;" onclick="triggerLanguage(' + data.Language[i].value + ',this)">' + data.Language[i].name + '</a></li>');
                        }
                    </script>
                </ul>
            </span>
        </div>
    </div>
    <div class="row">
        <div class="span1">
            <span class="btn btn-info prebtn">搜索</span>
        </div>
        <div class="span10">
            <input type="text" name="journalName" value="@ViewBag.JournalName" />
            <input type="submit" class="btn btn-primary" style="margin-bottom:10px" value="查询" />
        </div>
    </div>
    </form>
</div>
<!-- Journals -->
@{
    ItemListBox<Periodical> data = ViewBag.Data;
    if (data != null && data.Data != null && data.Data.Any())
    {
        for (int row = 0, rlen = data.Data.Count / 3; row <= rlen; row++)
        {
    <div class="row">
        @{
            for (int i = row * 3; i < row * 3 + 3 && i < data.Data.Count; i++)
            {
            <div class="span4">
                <div class="span2 book">
                    <a target="_blank" href="/j/index/@data.Data[i].Id">
                        <img alt="@data.Data[i].Name" src="@data.Data[i].CoverImg" />
                    </a>
                </div>
                <div class="span2">
                    <h5>
                        <a target="_blank" href="/j/index/@data.Data[i].Id">@data.Data[i].Name</a></h5>
                    <p style="line-height:160%">
                        <strong>行业：</strong>@data.Data[i].IndType.Mapping() -- @data.Data[i].SubIndType.Mapping()<br />
                    
                        <strong>主办：</strong>@data.Data[i].ZBDW<br />
                    
                        <strong>类型：</strong>
                        @{
                var apts = data.Data[i].Aptitude.Split(';');
                if(apts!= null && apts.Any())
                {
                    foreach(var apt in apts)
                    {
                        if(String.IsNullOrEmpty(apt))
                        {
                            continue;
                        }
                        <span>@(((Aptitude)Int32.Parse(apt)).Mapping())</span>
                    }
                }
                            }
                        </p>
                    <p>
                        @if(user==null || user.SystemRole == UserRole.Member)
                        {
                            <a href="/m/submit/@data.Data[i].Id" class="btn btn-primary btn-mini">期刊投稿</a>
                        }
                        else
                        {
                            <a href="/j/index/@data.Data[i].Id" class="btn btn-info btn-mini">期刊约稿</a>
                        }
                    </p>
                </div>
            </div>
            }
        }
    </div>
        }
    }
    @Html.Raw(data.PageItemSegment)
        <div class="span12">
            <hr />
        </div>
}
@section tail{
    <script type="text/javascript">
        $(function () {
        $('#likindex').addClass('active');

        var indtype= @ViewBag.IndType;
        indtype = indtype == -1?0:parseInt(indtype,10)+1;
        $('#indtypenav').children('li').eq(indtype).addClass('active');

        var aptitude = @ViewBag.Aptitude;
        aptitude = aptitude == -1?0:parseInt(aptitude,10);
        aptitude = aptitude == 99?12:aptitude;
        $('#aptnav').children('li').eq(aptitude).addClass('active');

        var language = @ViewBag.Language;
        language = language == -1?0:language;
        language = language == 9?3:language;
        $('#aptlang').children('li').eq(language).addClass('active');        
    });
    function triggerIndType(indType, sender) {
        $(sender).parent().siblings('li').each(function () {
            $(this).removeClass('active');
        });
        $(sender).parent().addClass('active');
        $('#hidind').val(indType);
        $('#mlistform').submit();
    }
    function triggerApt(apt, sender) {
        $(sender).parent().siblings('li').each(function () {
            $(this).removeClass('active');
        });
        $(sender).parent().addClass('active');
        $('#hidapt').val(apt);
        $('#mlistform').submit();
    }
    function triggerLanguage(lang, sender) {
        $(sender).parent().siblings('li').each(function () {
            $(this).removeClass('active');
        });
        $(sender).parent().addClass('active');
        $('#hidlang').val(lang);
        $('#mlistform').submit();
    }
    </script>
}
